from .base_model import BaseModel
from django.db import models
from .student import Student
from .classinfo import ClassInfo
from .semester import Semester
from ckeditor_uploader.fields import RichTextUploadingField

class StudentComment(BaseModel):
    """学生评语模型"""
    student = models.ForeignKey(Student, on_delete=models.CASCADE, related_name='comments', verbose_name="学生")
    class_info = models.ForeignKey(ClassInfo, on_delete=models.CASCADE, related_name='student_comments', verbose_name="班级")
    semester = models.ForeignKey(Semester, on_delete=models.CASCADE, related_name='student_comments', verbose_name="学期")
    content =RichTextUploadingField(blank=True, verbose_name="评语内容")
    is_generated = models.BooleanField(default=False, verbose_name="是否已生成")

    def __str__(self):
        return f"{self.semester} {self.student.name} 的评语"

    class Meta:
        verbose_name = "学生评语"
        verbose_name_plural = "学生评语"
        unique_together = ('student', 'semester')  # 确保一个学期一个学生只有一份评语